package org.xqh.utils.txt;

import org.xqh.utils.file.ReadTxtFileUtils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName FileUtils
 * @Description TODO
 * @Author xuqianghui
 * @Date 2020/8/26 16:35
 * @Version 1.0
 */
public class FileUtilTest {

    public static void main(String[] args) throws IOException {
        String path = "D:\\work\\test\\";
        Base64 base64 = new Base64();
        File file = new File(path+"test.jpg");
        File file2 = new File(path+"tes2.jpg");
        BASE64Encoder encoder = new BASE64Encoder();
        byte[] bytes = FileUtils.readFileToByteArray(file);
//        String base64dd = BASE64DecodedMultipar
//        ListFile.byte2Base64String(bytes);
        List<String> list = ReadTxtFileUtils.readTxt(new File(path + "paid"));
        String base64dd = list.get(0);
//                BASE64DecodedMultipartFile.byte2Base64String(bytes);
        System.out.println(base64dd);

        MultipartFile mFile = BASE64DecodedMultipartFile.base64ToMultipart(base64dd);

//        String bstr = encoder.encode(FileUtils.readFileToByteArray(file));
//        String base64Str = base64.encodeAsString(FileUtils.readFileToByteArray(file));
//        System.out.println(bstr);
////        System.out.println(base64Str.split(",").length);
//        System.out.println("===============");
//        System.out.println("===============");
//        System.out.println("===============");
//        System.out.println(base64Str);
//        byte[] bytes = base64.decode(base64Str);
        FileUtils.writeByteArrayToFile(file2, mFile.getBytes());
    }

}
